package com.ys.controller.web.mail;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ys.config.MenuId;
import com.ys.entity.mail.MailTag;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.W;

@Controller
@RequestMapping("/web/mail/mailTag")
public class WebMailTagController {
	
	@Autowired
	private CommonApiService<MailTag> commonApiService;
	
	/*
	 * 新增
	 */
	@GetMapping("/toAdd")
	public String toAdd(Model model, HttpServletRequest request, HttpServletResponse response){

		try {
			MailTag entity = new MailTag();
			return commonApiService.toAdd(model, entity, MenuId.MAIL_Tag, null, null);
		} catch (Exception e) {
			e.printStackTrace();
			return W.error(model, e.getMessage());
		}
	}
	
	/*
	 * 编辑
	 */
	@GetMapping("/toEdit")
	public String toEdit(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id) throws Exception{
		if (id == null) {
			return W.error(model, "ID不能为空");
		}
		
		MailTag entity = new MailTag().setId(id).queryFirst();

		return commonApiService.toEdit(model, entity.getId(), new MailTag(), MenuId.MAIL_Tag, null, null);
	}
}